require('./index.css');
var _account_service = require('service/account-service');


var header = {
    // username : 'abcd',
    init : function(){
        this.bindEvents();
        this.loadAccountInfo();
        return this;
    },
    bindEvents : function(){
        $('#signout-button').click(
            function(){
                _account_service.signOut(
                    function(res){
                        window.location.reload();
                    },
                    function(errMsg){
                        // doNothing
                        console.log(errMsg);
                    }
                )
            }
        );
    },
    loadAccountInfo : function(){
        var _this = this;
        _account_service.checkLogin(
            function(res){
                _this.username = res.username;
                console.log("......"+_this.username);
                $('.signOut').show();
                $('.signOn').hide();
            },
            function(errMsg){
                // console.log("error......"+errMsg);
                $('.signOut').hide();
                $('.signOn').show();
            }
        );
    }
};

module.exports = header.init();